package com.nuance.assignment.fileInfo.client.presenter;

import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.RootPanel;
import com.nuance.assignment.fileInfo.client.presenter.FileInfoPresenter.View;
import com.nuance.assignment.fileInfo.client.util.FileInfoConstants;
import com.nuance.assignment.fileInfo.client.view.FileInfoDataProvider;

/**
 * A presenter implementation for presenting FileInfoView
 * 
 * 
 * @author parag
 *
 */
public class FileInfoPresenter implements Presenter<View> {
	
	/**
	 * All UI widgets wanting to be supported by this presenter must implement
	 * this interface
	 * 
	 * @author parag
	 *
	 */
	public static interface View extends IsWidget{
		public void setFileInfoDataProvider(FileInfoDataProvider fileInfoDataProvider);
	}

	private final FileInfoDataProvider fileInfoDataProvider;
	
	public FileInfoPresenter(FileInfoConstants fileInfoConstants) {
		fileInfoDataProvider = new FileInfoDataProvider(fileInfoConstants);
	}
	
	/**
	 * Present given View implementation and add it to the root
	 * 
	 * @see com.nuance.assignment.fileInfo.client.presenter.Presenter#present(com.google.gwt.user.client.ui.IsWidget)
	 */
	@Override
	public void present(View fileInfoView) {
		fileInfoView.setFileInfoDataProvider(fileInfoDataProvider);
		if(!fileInfoView.asWidget().isAttached()){
			RootPanel.get().add(fileInfoView);
		}
	}

}
